package com.edais.actions;

import com.edais.domain.UnbindingCardApply;
import com.edais.domain.UserRecePayCard;
import com.edais.domain.WeixinMediaBinding;
import com.edais.service.*;
import com.edais.util.CommonUtil;
import com.edais.util.Consts;
import com.edais.util.JsonUtil;
import com.edais.util.Message;
import com.edais.util.weixinAbout.SendWeiXinUtil;
import com.edais.util.zsht.ZSHTPayThridPartyFunctionUtil;
import com.yunzhi.domain.RequestHeader;
import com.yunzhi.domain.ResultCode;
import com.yunzhi.domain.ResultConstant;
import com.yunzhi.domain.ResultDTO;
import com.yunzhi.util.RequestUtil;
import com.yunzhi.util.ResponseUtil;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@Controller
@RequestMapping("/userCard")

public class UserCardAction implements Serializable {
	private static final Log logger = LogFactory.getLog(UserCardAction.class);

	@Autowired
	private UserCardService userCardService;
	
	@Autowired
	private UserService userService;
	
	@Autowired
	private WeixinBindingService weixinBindingService;
	
	@Autowired
	private CaptchaService captchaService;
	
	@Autowired
	private SMSService sMSService;
	
	@Autowired
	private CenterService centerService;

	/**
	 * 根据用户Id获取用户已绑定银行卡信息
	 * 
	 * @param request
	 * @param response
	 */
	@RequestMapping(value = "/getUserBankCardInfo")
	public void getUserBankCardInfo(HttpServletRequest request,
			HttpServletResponse response) {
		Map<String, Object> jsonMap = new HashMap<String, Object>();
		// 解密请求参数
		Map<String, String> paramsMap = CommonUtil.decryptParamters(request);
		String userId = paramsMap.get("userId");// 用户id

		if (StringUtils.isBlank(userId)) {
			String result = CommonUtil.setResultStringCn(
					new HashMap<String, Object>(), Consts.ERROR_CODE,
					Consts.ErrorMsg.MSG00001,
					Message.CnDescriptionExpression.BUSINESSE_ERROR);

			// 处理返回结果
			CommonUtil.responseJson(result, response);
			logger.debug("userCard/getUserBankCardInfo 传入用户id为空");
			return;
		}

		try {
			Map<String, Object> requestMap = new HashMap<String, Object>();
			requestMap.put("userId", userId);
			jsonMap = this.userCardService
					.queryUserCardInfoByUserId(requestMap);

			// 处理返回结果
			String result = JsonUtil.getJsonStringFromMap(jsonMap);
			CommonUtil.responseJson(result, response);
		} catch (Exception e) {
			logger.error("userCard/getUserBankCardInfo 异常:" + e.getCause());
			String result = CommonUtil.setResultStringCn(
					new HashMap<String, Object>(), Consts.ERROR_CODE,
					Consts.ErrorMsg.MSG00001,
					Message.CnDescriptionExpression.BUSINESSE_ERROR);
			CommonUtil.responseJson(result, response);
		}
	}

	/**
	 * 根据绑定请求号查询银行卡信息
	 * 
	 * @param request
	 * @param response
	 */
	@RequestMapping(value = "/updateUserBankCardByReqNum")
	public void updateUserBankCardByReqNum(HttpServletRequest request,
			HttpServletResponse response) {
		Map<String, Object> jsonMap = new HashMap<String, Object>();
		// 解密请求参数
		Map<String, String> paramsMap = CommonUtil.decryptParamters(request);
		String bindingReqNum = paramsMap.get("bindingReqNum");
		String noAgree = paramsMap.get("noAgree");
		String moneyOrder = paramsMap.get("moneyOrder");
		String oidPayBill = paramsMap.get("oidPayBill");
		String reqStr = paramsMap.get("reqStr");
		String payFlay = paramsMap.get("payFlag");
		String logTitle = "rechargeNotify"+bindingReqNum;
		logger.info(logTitle + "调用核心：" + paramsMap.toString());
		if (StringUtils.isBlank(bindingReqNum)) {
			String result = CommonUtil.setResultStringCn(
					new HashMap<String, Object>(), Consts.ERROR_CODE,
					Consts.ErrorMsg.MSG00001,
					"userCard/queryBankCardByBindingReqNum 传入请求号为空");

			// 处理返回结果
			CommonUtil.responseJson(result, response);
			logger.debug("userCard/queryBankCardByBindingReqNum 传入请求号为空");
			return;
		}
		/*if (StringUtils.isBlank(noAgree)) {
			String result = CommonUtil.setResultStringCn(
					new HashMap<String, Object>(), Consts.ERROR_CODE,
					Consts.ErrorMsg.MSG00001,
					Message.CnDescriptionExpression.BUSINESSE_ERROR);

			// 处理返回结果
			CommonUtil.responseJson(result, response);
			logger.debug("userCard/queryBankCardByBindingReqNum 传入签约协议号为空");
			return;
		}*/
		if (StringUtils.isBlank(moneyOrder)) {
			String result = CommonUtil.setResultStringCn(
					new HashMap<String, Object>(), Consts.ERROR_CODE,
					Consts.ErrorMsg.MSG00001,
					"userCard/queryBankCardByBindingReqNum 传入充值金额为空");

			// 处理返回结果
			CommonUtil.responseJson(result, response);
			logger.debug("userCard/queryBankCardByBindingReqNum 传入充值金额为空");
			return;
		}
		if (StringUtils.isBlank(oidPayBill)) {
			String result = CommonUtil.setResultStringCn(
					new HashMap<String, Object>(), Consts.ERROR_CODE,
					Consts.ErrorMsg.MSG00001,
					"userCard/queryBankCardByBindingReqNum 传入连连支付订单号为空");

			// 处理返回结果
			CommonUtil.responseJson(result, response);
			logger.debug("userCard/queryBankCardByBindingReqNum 传入连连支付订单号为空");
			return;
		}
		try {
			Map<String, Object> requestMap = new HashMap<String, Object>();
			requestMap.put("bindingReqNum", bindingReqNum);
			requestMap.put("noAgree", noAgree);
			requestMap.put("moneyOrder", moneyOrder);
			requestMap.put("oidPayBill", oidPayBill);
			requestMap.put("reqStr", reqStr);
			requestMap.put("payFlay", payFlay);
			
			jsonMap = this.userCardService.coreLLPayNotify(requestMap);
			
			if(Consts.SUCCESS_CODE.equals(jsonMap.get("rescode"))){
				String userId = String.valueOf(jsonMap.get("userId")==null?"":jsonMap.get("userId"));
				//发送短信或微信
				sendMeidaAndSMS(userId,paramsMap, moneyOrder);
				//发送个推消息----add by gongyanlan
				String smsNo="sms01001";//充值,config_sms表中参数,
				String mobile = captchaService.getMobileById(userId);//通过用户ID查询使用手机号
				String[] smsParams={moneyOrder,"",""};
				Map<String,Object> map=new HashMap<String,Object>();
				map.put("userId", userId);
				map.put("mobile", mobile);
				map.put("title", "充值成功通知");//标题
				map.put("messageDetailTypeNew", "3");//1.订制商品个人消息，2.还款成功，3.充值，4.投资，5,提现
				map.put("messageDetailResult", "0");//0.执行成功消息提示，1.执行失败提示
				map.put("smsParams", smsParams);//消息模板里需要替换的变量
				map.put("smsNo", smsNo);
				sMSService.sendGetuiMSG(map);
			}else if("99998".equals(jsonMap.get("rescode"))){
				jsonMap.put("rescode", Consts.SUCCESS_CODE);
			}
			logger.info(logTitle + "调用核心结果：" + jsonMap.get("rescode"));
			// 处理返回结果
			String result = JsonUtil.getJsonStringFromMap(jsonMap);
			CommonUtil.responseJson(result, response);
			
			logger.info("====================JavaService连连支付成功回调接口结束=======================");
		} catch (Exception e) {
			logger.error("userCard/queryBankCardByBindingReqNum 异常:"
					+ e.getCause());
			String result = CommonUtil.setResultStringCn(
					new HashMap<String, Object>(), Consts.ERROR_CODE,
					Consts.ErrorMsg.MSG00001,
					Message.CnDescriptionExpression.BUSINESSE_ERROR);
			CommonUtil.responseJson(result, response);
		}
	}

	/**
	 * 根据USERID发送短信/微信
	 * @param userId
	 */
	public void sendMeidaAndSMS(String userId,Map<String,String> paramsMap,String moneyOrder) throws Exception{
		//封装用户ID
		WeixinMediaBinding mediaBinding = new WeixinMediaBinding();
		mediaBinding.setUserId(Integer.parseInt(userId));
		
		//先推送微信，微信成功不发短信，失败再发短信
		String mobile = captchaService.getMobileById(userId);//通过用户ID查询使用手机号
		String mediaUid = weixinBindingService.queryMediaUid(mediaBinding);//通过用户ID实体类查询微信标识
		
		//TODO 逻辑判断
		if(null == mediaUid || "null".equalsIgnoreCase(mediaUid) || "".equalsIgnoreCase(mediaUid)){
			logger.info("[推送短信息]因手机号："+mobile+"并未绑定微信");
			//发送短信
			String cpType="";
			String smsNo="sms01001";//config_sms表中参数
			String tsje=moneyOrder;
			if (StringUtils.isBlank(userId) 
					|| StringUtils.isBlank(smsNo)|| StringUtils.isBlank(tsje)) {
				logger.debug("deposit/join sendSMS 传入参数为空");
			}
			try{
				// 发送短信
				if(StringUtils.isEmpty(cpType)){
					 sMSService.getSMS(userId,smsNo,tsje);	
				}else{
					sMSService.getSMS(userId,smsNo,tsje,cpType);	
				}
			} catch (Exception e) {
				logger.error("deposit/join sendSMS异常:" + e.getCause());
			}
		}else{
			Map<String,String> weixinTMap = new HashMap<String,String>();
			weixinTMap.put("mediaUid", mediaUid);//微信用户唯一标识 
			weixinTMap.put("money", moneyOrder);//充值金额
			weixinTMap.put("functionScope", "recharge");//推送类型
			
			boolean sendRusult = SendWeiXinUtil.sendWeiXin(weixinTMap);
			if(!sendRusult){
				logger.info("[微信推送失败][推送短信息]因手机号："+mobile+"并未绑定微信或者未关注联币钱包微信号");
				//发送短信
				String cpType="";
				String smsNo="sms01001";//config_sms表中参数
				String tsje=moneyOrder;
				if (StringUtils.isBlank(userId) 
						|| StringUtils.isBlank(smsNo)|| StringUtils.isBlank(tsje)) {
					logger.debug("deposit/join sendSMS 传入参数为空");
				}
				try{
					// 发送短信
					if(StringUtils.isEmpty(cpType)){
						 sMSService.getSMS(userId,smsNo,tsje);	
					}else{
						sMSService.getSMS(userId,smsNo,tsje,cpType);	
					}
				} catch (Exception e) {
					logger.error("deposit/join sendSMS异常:" + e.getCause());
				}
			}else{
				logger.info("[微信推送]手机号："+mobile+"推送成功");
			}
		}
	}
	
	/**
	 * 连连支付-根据用户银行卡查询银行卡卡bin信息
	 * 
	 * @param request
	 * @param response
	 */
	@RequestMapping(value = "/queryCardBinLLPay")
	public void queryCardBinLLPay(HttpServletRequest request,
			HttpServletResponse response) {
		Map<String, String> jsonMap = new HashMap<String, String>();
		// 解密请求参数
		Map<String, String> paramsMap = CommonUtil.decryptParamters(request);
		String cardNo = paramsMap.get("cardNo");// 银行卡卡号
		String payType = paramsMap.get("payType");// 支付类型

		if (StringUtils.isBlank(cardNo)) {
			String result = CommonUtil.setResultStringCn(
					new HashMap<String, Object>(), Consts.ERROR_CODE,
					Consts.ErrorMsg.MSG00001,
					Message.CnDescriptionExpression.BUSINESSE_ERROR);

			// 处理返回结果
			CommonUtil.responseJson(result, response);
			logger.debug("userCard/queryCardBinLL 传入银行卡号为空");
			return;
		}

		try {
			Map<String, String> requestMap = new HashMap<String, String>();
			requestMap.put("cardNo", cardNo);
			requestMap.put("payType", payType);
			jsonMap = this.userCardService.queryCardBinLL(requestMap);

			// 处理返回结果
			String result = JsonUtil.getJsonStringFromMap(jsonMap);
			CommonUtil.responseJson(result, response);
		} catch (Exception e) {
			logger.error("userCard/queryCardBinLLPay 异常:" + e.getCause());
			String result = CommonUtil.setResultStringCn(
					new HashMap<String, Object>(), Consts.ERROR_CODE,
					Consts.ErrorMsg.MSG00001,
					Message.CnDescriptionExpression.BUSINESSE_ERROR);
			CommonUtil.responseJson(result, response);
		}
	}

	/**
	 * 连连支付-查询用户签约信息
	 * 
	 * @param request
	 * @param response
	 */
	@RequestMapping(value = "/queryUserSignInfo")
	public void queryUserSignInfo(HttpServletRequest request,
			HttpServletResponse response) {
		Map<String, String> jsonMap = new HashMap<String, String>();
		// 解密请求参数
		Map<String, String> paramsMap = CommonUtil.decryptParamters(request);
		String userId = paramsMap.get("userId");// 用户Id
		String payType = paramsMap.get("payType");// 支付类型

		if (StringUtils.isBlank(userId)) {
			String result = CommonUtil.setResultStringCn(
					new HashMap<String, Object>(), Consts.ERROR_CODE,
					Consts.ErrorMsg.MSG00001,
					Message.CnDescriptionExpression.BUSINESSE_ERROR);

			// 处理返回结果
			CommonUtil.responseJson(result, response);
			logger.debug("userCard/queryCardBinLL 传入UserId为空");
			return;
		}

		try {
			Map<String, String> requestMap = new HashMap<String, String>();
			requestMap.put("userId", userId);
			requestMap.put("payType", payType);
			jsonMap = this.userCardService.queryUserSignInfo(requestMap);

			// 处理返回结果
			String result = JsonUtil.getJsonStringFromMap(jsonMap);
			CommonUtil.responseJson(result, response);
		} catch (Exception e) {
			logger.error("userCard/queryCardBinLLPay 异常:" + e.getCause());
			String result = CommonUtil.setResultStringCn(
					new HashMap<String, Object>(), Consts.ERROR_CODE,
					Consts.ErrorMsg.MSG00001,
					Message.CnDescriptionExpression.BUSINESSE_ERROR);
			CommonUtil.responseJson(result, response);
		}

	}

	/**
	 * 保存银行卡信息
	 * 
	 * @param request
	 * @param response
	 */
	@RequestMapping(value = "/saveUserBankCardInfo")
	public void saveUserBankCardInfo(HttpServletRequest request,
			HttpServletResponse response) {
		Map<String, String> jsonMap = new HashMap<String, String>();
		// 解密请求参数
		Map<String, String> requestMap = CommonUtil.decryptParamters(request);
		String userId = requestMap.get("userId");
		String cardNo = requestMap.get("cardNo");
		String bankCode = requestMap.get("bankCode");
		String bankName = requestMap.get("bankName");
		String bindindReqNum = requestMap.get("bindindReqNum");
		String acctName = requestMap.get("acctName");
		String idCard = requestMap.get("idCard");
		String cardPhone = requestMap.get("cardPhone");

		// 非空判断
		if (StringUtils.isBlank(userId)) {
			String result = CommonUtil.setResultStringCn(
					new HashMap<String, Object>(), Consts.ERROR_CODE,
					Consts.ErrorMsg.MSG00001,
					Message.CnDescriptionExpression.BUSINESSE_ERROR);

			// 处理返回结果
			CommonUtil.responseJson(result, response);
			logger.debug("userCard/saveUserBankCardInfo 传入UserId为空");
			return;
		}

		if (StringUtils.isBlank(cardNo)) {
			String result = CommonUtil.setResultStringCn(
					new HashMap<String, Object>(), Consts.ERROR_CODE,
					Consts.ErrorMsg.MSG00001,
					Message.CnDescriptionExpression.BUSINESSE_ERROR);

			// 处理返回结果
			CommonUtil.responseJson(result, response);
			logger.debug("userCard/saveUserBankCardInfo 传入银行卡卡号为空");
			return;
		}

		if (StringUtils.isBlank(bankCode)) {
			String result = CommonUtil.setResultStringCn(
					new HashMap<String, Object>(), Consts.ERROR_CODE,
					Consts.ErrorMsg.MSG00001,
					Message.CnDescriptionExpression.BUSINESSE_ERROR);

			// 处理返回结果
			CommonUtil.responseJson(result, response);
			logger.debug("userCard/saveUserBankCardInfo 传入银行卡编号为空");
			return;
		}
		if (StringUtils.isBlank(bankName)) {
			String result = CommonUtil.setResultStringCn(
					new HashMap<String, Object>(), Consts.ERROR_CODE,
					Consts.ErrorMsg.MSG00001,
					Message.CnDescriptionExpression.BUSINESSE_ERROR);

			// 处理返回结果
			CommonUtil.responseJson(result, response);
			logger.debug("userCard/saveUserBankCardInfo 传入银行卡名称为空");
			return;
		}
		if (StringUtils.isBlank(bindindReqNum)) {
			String result = CommonUtil.setResultStringCn(
					new HashMap<String, Object>(), Consts.ERROR_CODE,
					Consts.ErrorMsg.MSG00001,
					Message.CnDescriptionExpression.BUSINESSE_ERROR);

			// 处理返回结果
			CommonUtil.responseJson(result, response);
			logger.debug("userCard/saveUserBankCardInfo 传入请求号为空");
			return;
		}
		if (StringUtils.isBlank(acctName)) {
			String result = CommonUtil.setResultStringCn(
					new HashMap<String, Object>(), Consts.ERROR_CODE,
					Consts.ErrorMsg.MSG00001,
					Message.CnDescriptionExpression.BUSINESSE_ERROR);

			// 处理返回结果
			CommonUtil.responseJson(result, response);
			logger.debug("userCard/saveUserBankCardInfo 传入用户真实姓名为空");
			return;
		}
		if (StringUtils.isBlank(idCard)) {
			String result = CommonUtil.setResultStringCn(
					new HashMap<String, Object>(), Consts.ERROR_CODE,
					Consts.ErrorMsg.MSG00001,
					Message.CnDescriptionExpression.BUSINESSE_ERROR);

			// 处理返回结果
			CommonUtil.responseJson(result, response);
			logger.debug("userCard/saveUserBankCardInfo 传入身份证为空");
			return;
		}
		try {
			//鉴权通道
			
			jsonMap = this.userCardService.saveUserBankCardInfo(requestMap);

			// 处理返回结果
			String result = JsonUtil.getJsonStringFromMap(jsonMap);
			CommonUtil.responseJson(result, response);
		} catch (Exception e) {
			logger.error("userCard/saveUserBankCardInfo 异常:" + e.getCause());
			String result = CommonUtil.setResultStringCn(
					new HashMap<String, Object>(), Consts.ERROR_CODE,
					Consts.ErrorMsg.MSG00001,
					Message.CnDescriptionExpression.BUSINESSE_ERROR);
			CommonUtil.responseJson(result, response);
		}

	}

	/**
	 * 连连支付后更新银行卡信息
	 * 
	 * @param request
	 * @param response
	 */
	@RequestMapping(value = "/updateUserBindindBankCardInfo")
	public void updateUserBindindBankCardInfo(HttpServletRequest request,
			HttpServletResponse response) {
		Map<String, Object> jsonMap = new HashMap<String, Object>();
		// 解密请求参数
		Map<String, String> requestMap = CommonUtil.decryptParamters(request);
		String userId = requestMap.get("userId");
		String cardNumber = requestMap.get("cardNo");
		String bindingReqNum = requestMap.get("bindindReqNum");
		String cardPhone = requestMap.get("cardPhone");
		// 非空判断
		if (StringUtils.isBlank(userId)) {
			String result = CommonUtil.setResultStringCn(
					new HashMap<String, Object>(), Consts.ERROR_CODE,
					Consts.ErrorMsg.MSG00001,
					Message.CnDescriptionExpression.BUSINESSE_ERROR);

			// 处理返回结果
			CommonUtil.responseJson(result, response);
			logger.debug("userCard/updateUserBindindBankCardInfo 传入UserId为空");
			return;
		}

		if (StringUtils.isBlank(cardNumber)) {
			String result = CommonUtil.setResultStringCn(
					new HashMap<String, Object>(), Consts.ERROR_CODE,
					Consts.ErrorMsg.MSG00001,
					Message.CnDescriptionExpression.BUSINESSE_ERROR);

			// 处理返回结果
			CommonUtil.responseJson(result, response);
			logger.debug("userCard/updateUserBindindBankCardInfo 传入银行卡卡号为空");
			return;
		}
		if (StringUtils.isBlank(bindingReqNum)) {
			String result = CommonUtil.setResultStringCn(
					new HashMap<String, Object>(), Consts.ERROR_CODE,
					Consts.ErrorMsg.MSG00001,
					Message.CnDescriptionExpression.BUSINESSE_ERROR);

			// 处理返回结果
			CommonUtil.responseJson(result, response);
			logger.debug("userCard/updateUserBindindBankCardInfo 传入请求号为空");
			return;
		}

		try {
			Map<String, Object> paramsMap = new HashMap<String, Object>();
			paramsMap.put("userId", userId);
			paramsMap.put("cardNumber", cardNumber);
			paramsMap.put("bindingReqNum", bindingReqNum);
			paramsMap.put("cardPhone", cardPhone);
			jsonMap = this.userCardService
					.updateUserBindindBankCardInfo(paramsMap);

			// 处理返回结果
			String result = JsonUtil.getJsonStringFromMap(jsonMap);
			CommonUtil.responseJson(result, response);
		} catch (Exception e) {
			logger.error("userCard/saveUserBankCardInfo 异常:" + e.getCause());
			String result = CommonUtil.setResultStringCn(
					new HashMap<String, Object>(), Consts.ERROR_CODE,
					Consts.ErrorMsg.MSG00001,
					Message.CnDescriptionExpression.BUSINESSE_ERROR);
			CommonUtil.responseJson(result, response);
		}

	}

	/**
	 * 预支付订单信息
	 * 
	 * @param request
	 * @param response
	 */
	@RequestMapping(value = "/dealLLPayFastPayToken")
	public void dealLLPayFastPayToken(HttpServletRequest request,
			HttpServletResponse response) {
		Map<String, Object> jsonMap = new HashMap<String, Object>();
		// 解密请求参数
		Map<String, String> requestMap = CommonUtil.decryptParamters(request);
		String userId = requestMap.get("userId");
		String moneyOrder = requestMap.get("moneyOrder");
		String signSrc = requestMap.get("signSrc");

		String noOrder = requestMap.get("noOrder");
		String oidPartner = requestMap.get("oidPartner");
		String dtOrder = requestMap.get("dtOrder");
		//充值渠道
		String rechargeChannel = requestMap.get("rechargeChannel");
		//银行卡卡号
		String cardNumber = requestMap.get("cardNumber");
		String platform = requestMap.get("platform");
		
		// 非空判断
		if (StringUtils.isBlank(userId)) {
			String result = CommonUtil.setResultStringCn(
					new HashMap<String, Object>(), Consts.ERROR_CODE,
					Consts.ErrorMsg.MSG00001,
					Message.CnDescriptionExpression.BUSINESSE_ERROR);

			// 处理返回结果
			CommonUtil.responseJson(result, response);
			logger.debug("userCard/dealLLPayFastPayToken 传入UserId为空");
			return;
		}
		
		if (StringUtils.isBlank(rechargeChannel)) {
			String result = CommonUtil.setResultStringCn(
					new HashMap<String, Object>(), Consts.ERROR_CODE,
					Consts.ErrorMsg.MSG00001,
					Message.CnDescriptionExpression.BUSINESSE_ERROR);

			// 处理返回结果
			CommonUtil.responseJson(result, response);
			logger.debug("userCard/dealLLPayFastPayToken 传入充值渠道为空");
			return;
		}

		if (StringUtils.isBlank(moneyOrder)) {
			String result = CommonUtil.setResultStringCn(
					new HashMap<String, Object>(), Consts.ERROR_CODE,
					Consts.ErrorMsg.MSG00001,
					Message.CnDescriptionExpression.BUSINESSE_ERROR);

			// 处理返回结果
			CommonUtil.responseJson(result, response);
			logger.debug("userCard/dealLLPayFastPayToken 传入充值金额为空");
			return;
		}

		if (StringUtils.isBlank(signSrc)) {
			String result = CommonUtil.setResultStringCn(
					new HashMap<String, Object>(), Consts.ERROR_CODE,
					Consts.ErrorMsg.MSG00001,
					Message.CnDescriptionExpression.BUSINESSE_ERROR);

			// 处理返回结果
			CommonUtil.responseJson(result, response);
			logger.debug("userCard/dealLLPayFastPayToken 传入上送报文为空");
			return;
		}

		if (StringUtils.isBlank(noOrder)) {
			String result = CommonUtil.setResultStringCn(
					new HashMap<String, Object>(), Consts.ERROR_CODE,
					Consts.ErrorMsg.MSG00001,
					Message.CnDescriptionExpression.BUSINESSE_ERROR);

			// 处理返回结果
			CommonUtil.responseJson(result, response);
			logger.debug("userCard/dealLLPayFastPayToken 传入订单号为空");
			return;
		}
		if (StringUtils.isBlank(oidPartner)) {
			String result = CommonUtil.setResultStringCn(
					new HashMap<String, Object>(), Consts.ERROR_CODE,
					Consts.ErrorMsg.MSG00001,
					Message.CnDescriptionExpression.BUSINESSE_ERROR);

			// 处理返回结果
			CommonUtil.responseJson(result, response);
			logger.debug("userCard/dealLLPayFastPayToken 传入商户号为空");
			return;
		}
		if (StringUtils.isBlank(dtOrder)) {
			String result = CommonUtil.setResultStringCn(
					new HashMap<String, Object>(), Consts.ERROR_CODE,
					Consts.ErrorMsg.MSG00001,
					Message.CnDescriptionExpression.BUSINESSE_ERROR);

			// 处理返回结果
			CommonUtil.responseJson(result, response);
			logger.debug("userCard/dealLLPayFastPayToken 传入交易时间为空");
			return;
		}
		if (StringUtils.isBlank(platform)) {
			String result = CommonUtil.setResultStringCn(
					new HashMap<String, Object>(), Consts.ERROR_CODE,
					Consts.ErrorMsg.MSG00001,
					Message.CnDescriptionExpression.BUSINESSE_ERROR);
			
			// 处理返回结果
			CommonUtil.responseJson(result, response);
			logger.debug("userCard/dealLLPayFastPayToken 传入platform为空");
			return;
		}

		try {
			Map<String, Object> paramsMap = new HashMap<String, Object>();
			paramsMap.put("userId", userId);
			paramsMap.put("moneyOrder", moneyOrder);
			paramsMap.put("signSrc", signSrc);
			paramsMap.put("noOrder", noOrder);
			paramsMap.put("oidPartner", oidPartner);
			paramsMap.put("dtOrder", dtOrder);
			paramsMap.put("rechargeChannel", rechargeChannel);
			paramsMap.put("cardNumber", StringUtils.isNotBlank(cardNumber)?cardNumber:"");
			paramsMap.put("platform", platform);

			jsonMap = this.userCardService.dealLLPayFastPayToken(paramsMap);

			// 处理返回结果
			String result = JsonUtil.getJsonStringFromMap(jsonMap);
			CommonUtil.responseJson(result, response);
		} catch (Exception e) {
			logger.error("userCard/dealLLPayFastPayToken 异常:" + e.getCause());
			String result = CommonUtil.setResultStringCn(
					new HashMap<String, Object>(), Consts.ERROR_CODE,
					Consts.ErrorMsg.MSG00001,
					Message.CnDescriptionExpression.BUSINESSE_ERROR);
			CommonUtil.responseJson(result, response);
		}
	}

	/**
	 * 连连支付-提现回调
	 * （非空项resultPay-支付结果，noOrder，moneyOrder，dtOrder）
	 * @param request
	 * @param response
	 */
	@RequestMapping(value = "/llpayWithdrawalsNotify")
	public void llpayWithdrawalsNotify(HttpServletRequest request,
			HttpServletResponse response) {
		Map<String, Object> jsonMap = new HashMap<String, Object>();
		// 解密请求参数
		Map<String, String> requestMap = CommonUtil.decryptParamters(request);
		String resultPay = requestMap.get("resultPay");
		String noOrder = requestMap.get("noOrder");
		String moneyOrder = requestMap.get("moneyOrder");
		String dtOrder = requestMap.get("dtOrder");
		String oidPaybill = requestMap.get("oidPaybill");
		String settleDate = requestMap.get("settleDate");
		String errorFlag = requestMap.get("errorFlag");
		// 非空判断
		if (StringUtils.isBlank(resultPay)) {
			String result = CommonUtil.setResultStringCn(
					new HashMap<String, Object>(), Consts.ERROR_CODE,
					Consts.ErrorMsg.MSG00001,
					Message.CnDescriptionExpression.BUSINESSE_ERROR);

			// 处理返回结果
			CommonUtil.responseJson(result, response);
			logger.debug("userCard/dealLLPayFastPayToken 传入resultPay为空");
			return;
		}
		if (StringUtils.isBlank(noOrder)) {
			String result = CommonUtil.setResultStringCn(
					new HashMap<String, Object>(), Consts.ERROR_CODE,
					Consts.ErrorMsg.MSG00001,
					Message.CnDescriptionExpression.BUSINESSE_ERROR);

			// 处理返回结果
			CommonUtil.responseJson(result, response);
			logger.debug("userCard/dealLLPayFastPayToken 传入noOrder为空");
			return;
		}
		if (StringUtils.isBlank(moneyOrder)) {
			String result = CommonUtil.setResultStringCn(
					new HashMap<String, Object>(), Consts.ERROR_CODE,
					Consts.ErrorMsg.MSG00001,
					Message.CnDescriptionExpression.BUSINESSE_ERROR);

			// 处理返回结果
			CommonUtil.responseJson(result, response);
			logger.debug("userCard/dealLLPayFastPayToken 传入moneyOrder为空");
			return;
		}
		if (StringUtils.isBlank(dtOrder)) {
			String result = CommonUtil.setResultStringCn(
					new HashMap<String, Object>(), Consts.ERROR_CODE,
					Consts.ErrorMsg.MSG00001,
					Message.CnDescriptionExpression.BUSINESSE_ERROR);

			// 处理返回结果
			CommonUtil.responseJson(result, response);
			logger.debug("userCard/dealLLPayFastPayToken 传入dtOrder为空");
			return;
		}

		try {
			Map<String, Object> paramsMap = new HashMap<String, Object>();
			paramsMap.put("resultPay", resultPay);
			paramsMap.put("noOrder", noOrder);
			paramsMap.put("moneyOrder", moneyOrder);
			paramsMap.put("dtOrder", dtOrder);
			paramsMap.put("oidPaybill", oidPaybill);
			paramsMap.put("settleDate", settleDate);
			if(StringUtils.isNotBlank(errorFlag)){
				paramsMap.put("errorFlag", errorFlag);
			}
			
			jsonMap = this.userCardService.llpayWithdrawalsNotify(paramsMap);

			/**删除redis里我的账户数据*/
            /*String userId = jsonMap.get("userId").toString();*/
			// 处理返回结果
			String result = JsonUtil.getJsonStringFromMap(jsonMap);
			CommonUtil.responseJson(result, response);
		} catch (Exception e) {
			logger.error("userCard/dealLLPayFastPayToken 异常:" + e.getCause());
			String result = CommonUtil.setResultStringCn(
					new HashMap<String, Object>(), Consts.ERROR_CODE,
					Consts.ErrorMsg.MSG00001,
					Message.CnDescriptionExpression.BUSINESSE_ERROR);
			CommonUtil.responseJson(result, response);
		}
	}

	/**
	 * 富友-提现回调
	 *
	 * @param request
	 * @param response
	 */
	@RequestMapping(value = "/fuyouWithdrawalsNotify")
	public void fuyouWithdrawalsNotify(HttpServletRequest request,
									   HttpServletResponse response) {
		Map<String, Object> jsonMap = new HashMap<String, Object>();
		// 解密请求参数
		Map<String, String> requestMap = CommonUtil.decryptParamters(request);
		String orderno = requestMap.get("orderno"); //商户请求流水
		String merdt = requestMap.get("merdt"); //请求日期
		String fuorderno = requestMap.get("fuorderno"); //富友流水
		String accntno = requestMap.get("accntno"); //账号
		String accntnm = requestMap.get("accntnm"); //账户名称
		String amt = requestMap.get("amt"); //退票金额
		String resultPay = requestMap.get("resultPay"); //支付结果
		String mac = requestMap.get("mac"); //校验值

		// 非空判断
		if (StringUtils.isBlank(resultPay)) {
			String result = CommonUtil.setResultStringCn(
					new HashMap<String, Object>(), Consts.ERROR_CODE,
					Consts.ErrorMsg.MSG00001,
					Message.CnDescriptionExpression.BUSINESSE_ERROR);

			// 处理返回结果
			CommonUtil.responseJson(result, response);
			logger.debug("userCard/fuyouWithdrawalsNotify 传入resultPay为空");
			return;
		}

		try {
			Map<String, Object> paramsMap = new HashMap<String, Object>();
			paramsMap.put("resultPay", resultPay);
			paramsMap.put("noOrder", orderno);
			paramsMap.put("oidPaybill", fuorderno);

			jsonMap = this.userCardService.llpayWithdrawalsNotify(paramsMap);

			// 处理返回结果
			String result = JsonUtil.getJsonStringFromMap(jsonMap);
			CommonUtil.responseJson(result, response);
		} catch (Exception e) {
			logger.error("userCard/fuyouWithdrawalsNotify 异常:" + e.getCause());
			String result = CommonUtil.setResultStringCn(
					new HashMap<String, Object>(), Consts.ERROR_CODE,
					Consts.ErrorMsg.MSG00001,
					Message.CnDescriptionExpression.BUSINESSE_ERROR);
			CommonUtil.responseJson(result, response);
		}
	}



	/**
	 * 失败订单更新
	 * 
	 * @param request
	 * @param response
	 */
	@RequestMapping(value = "/topUpSuccessd")
	public void topUpSuccessd(HttpServletRequest request,
			HttpServletResponse response) {
		Map<String, Object> jsonMap = new HashMap<String, Object>();
		// 解密请求参数
		Map<String, String> requestMap = CommonUtil.decryptParamters(request);
		
		String userId = requestMap.get("userId");

		// 非空判断
		if (StringUtils.isBlank(userId)) {
			String result = CommonUtil.setResultStringCn(
					new HashMap<String, Object>(), Consts.ERROR_CODE,
					Consts.ErrorMsg.MSG00001,
					Message.CnDescriptionExpression.BUSINESSE_ERROR);

			// 处理返回结果
			CommonUtil.responseJson(result, response);
			logger.debug("userCard/dealLLPayFastPayToken 传入UserId为空");
			return;
		}
		try {
			Map<String, Object> paramsMap = new HashMap<String, Object>();
			paramsMap.put("userId", userId);
			
			jsonMap = this.userCardService.updateFailTopUpOrder(paramsMap);
			
			// 处理返回结果
			String result = JsonUtil.getJsonStringFromMap(jsonMap);
			CommonUtil.responseJson(result, response);
		}catch (Exception e) {
			logger.error("userCard/dealLLPayFastPayToken 异常:" + e.getCause());
			String result = CommonUtil.setResultStringCn(
					new HashMap<String, Object>(), Consts.ERROR_CODE,
					Consts.ErrorMsg.MSG00001,
					Message.CnDescriptionExpression.BUSINESSE_ERROR);
			CommonUtil.responseJson(result, response);
		}
		
	}
	
	/**
	 * 查询是否支持银行
	 * @param request
	 * @param response
	 */
	@RequestMapping(value = "/queryBankExistCode")
	public void queryBankExistCode(HttpServletRequest request,
			HttpServletResponse response) {
		Map<String, Object> jsonMap = new HashMap<String, Object>();
		// 解密请求参数
		Map<String, String> requestMap = CommonUtil.decryptParamters(request);
		String bankCode = requestMap.get("bankCode");
		if (StringUtils.isBlank(bankCode)) {
			String result = CommonUtil.setResultStringCn(
					new HashMap<String, Object>(), Consts.ERROR_CODE,
					Consts.ErrorMsg.MSG00001,
					Message.CnDescriptionExpression.BUSINESSE_ERROR);

			// 处理返回结果
			CommonUtil.responseJson(result, response);
			logger.debug("userCard/queryBankExistCode 传入bankCode为空");
			return;
		}
		try{
			Map<String, Object> paramsMap = new HashMap<String, Object>();
			paramsMap.put("bankCode", bankCode);
			jsonMap = this.userCardService.queryBankIdByBankCode(paramsMap);
			// 处理返回结果
			String result = JsonUtil.getJsonStringFromMap(jsonMap);
			CommonUtil.responseJson(result, response);
		}catch (Exception e) {
			logger.error("userCard/queryBankExistCode 异常:" + e.getCause());
			String result = CommonUtil.setResultStringCn(
					new HashMap<String, Object>(), Consts.ERROR_CODE,
					Consts.ErrorMsg.MSG00001,
					Message.CnDescriptionExpression.BUSINESSE_ERROR);
			CommonUtil.responseJson(result, response);
		}
	}
	
	
	@RequestMapping(value = "/coreLLPayNotify")
	public void coreLLPayNotify(HttpServletRequest request,
			HttpServletResponse response) {
		Map<String, Object> jsonMap = new HashMap<String, Object>();
		// 解密请求参数
		Map<String, String> paramsMap = CommonUtil.decryptParamters(request);
		String bindingReqNum = paramsMap.get("bindingReqNum");// 用户id
		String noAgree = paramsMap.get("noAgree");
		String moneyOrder = paramsMap.get("moneyOrder");
		String oidPayBill = paramsMap.get("oidPayBill");
		String reqStr = paramsMap.get("reqStr");
		String payFlay = paramsMap.get("payFlag");
		logger.info("====================JavaService进入连连支付成功回调接口=======================");
		if (StringUtils.isBlank(bindingReqNum)) {
			String result = CommonUtil.setResultStringCn(
					new HashMap<String, Object>(), Consts.ERROR_CODE,
					Consts.ErrorMsg.MSG00001,
					"userCard/coreLLPayNotify 传入请求号为空");

			// 处理返回结果
			CommonUtil.responseJson(result, response);
			logger.debug("userCard/coreLLPayNotify 传入请求号为空");
			return;
		}
		if (StringUtils.isBlank(moneyOrder)) {
			String result = CommonUtil.setResultStringCn(
					new HashMap<String, Object>(), Consts.ERROR_CODE,
					Consts.ErrorMsg.MSG00001,
					"userCard/coreLLPayNotify 传入充值金额为空");

			// 处理返回结果
			CommonUtil.responseJson(result, response);
			logger.debug("userCard/coreLLPayNotify 传入充值金额为空");
			return;
		}
		if (StringUtils.isBlank(oidPayBill)) {
			String result = CommonUtil.setResultStringCn(
					new HashMap<String, Object>(), Consts.ERROR_CODE,
					Consts.ErrorMsg.MSG00001,
					"userCard/coreLLPayNotify 传入连连支付订单号为空");

			// 处理返回结果
			CommonUtil.responseJson(result, response);
			logger.debug("userCard/coreLLPayNotify 传入连连支付订单号为空");
			return;
		}
		try {
			Map<String, Object> requestMap = new HashMap<String, Object>();
			requestMap.put("bindingReqNum", bindingReqNum);
			requestMap.put("noAgree", noAgree);
			requestMap.put("moneyOrder", moneyOrder);
			requestMap.put("oidPayBill", oidPayBill);
			requestMap.put("reqStr", reqStr);
			requestMap.put("payFlay", payFlay);
			
			jsonMap = this.userCardService.coreLLPayNotify(requestMap);
			
			// 处理返回结果
			String result = JsonUtil.getJsonStringFromMap(jsonMap);
			CommonUtil.responseJson(result, response);
			
			logger.info("====================JavaService连连支付成功回调接口结束=======================");
		} catch (Exception e) {
			logger.error("userCard/coreLLPayNotify 异常:"
					+ e.getCause());
			String result = CommonUtil.setResultStringCn(
					new HashMap<String, Object>(), Consts.ERROR_CODE,
					Consts.ErrorMsg.MSG00001,
					Message.CnDescriptionExpression.BUSINESSE_ERROR);
			CommonUtil.responseJson(result, response);
		}
	}
	
	/**
	 * 解绑银行卡修改为申请时直接解绑，update by zyj 2016-9-13
	 * @param request
	 * @param response
	 */
	@RequestMapping(value = "/addUnbindingCardApply")
	public void addUnbindingCardApply(HttpServletRequest request,
			HttpServletResponse response) {
		
		Map<String, Object> jsonMap = new HashMap<String, Object>();

		String logInfo = "解绑银行卡—addUnbindingCardApply ";
		logger.info(logInfo+"开始");
		//签名校验
		if (!RequestUtil.validSign(request)) {
			logger.info(logInfo+"无效签名");
			ResponseUtil.write(response, ResultConstant.INVALID_SIGN);
			return;
		}

		//token校验
		if (!RequestUtil.validToken(request)) {
			logger.info(logInfo+"无效token");
			ResponseUtil.write(response, ResultConstant.INVALID_TOKEN);
			return;
		}

		//未登录校验
		RequestHeader header = RequestUtil.decodeHeader(request);
		if (header.getUserId() == null) {
			logger.info(logInfo+"未登录");
			ResponseUtil.write(response, ResultConstant.NOT_LOGIN);
			return;
		}

		try{
		// 解密请求参数
		Map<String, Object> paramsMap = RequestUtil.decodeData(request);
		String userId =header.getUserId().toString();// 用户id
		String idCard = (String) paramsMap.get("idCard");
		logInfo=logInfo+userId;
		if (StringUtils.isBlank(idCard)) {
		    // 处理返回结果
			logger.debug(logInfo+" 传入身份证号为空");
			ResultDTO resultDTO=new ResultDTO(ResultCode.FAILED,"解绑银行卡数据检查失败：身份证号为空");
			ResponseUtil.write(response,resultDTO);
			return;
		}

			Map<String, Object> requestMap = new HashMap<String, Object>();
			requestMap.put("userId", userId);
			requestMap.put("idCard", idCard.toUpperCase());

			ResultDTO resultDTO = this.userCardService.addUnbindingCardApply(requestMap,logInfo);

			if(resultDTO.codeEq(ResultCode.SUCCESS)){
				//异步解绑银行卡
				UserRecePayCard userRecePayCard = (UserRecePayCard) jsonMap.get("userRecePayCard");
				UnbindingCardApply newApply = (UnbindingCardApply) jsonMap.get("newApply");
				userService.unbindingCard(userRecePayCard, newApply);
			}
			logger.info(logInfo+"结束");
			// 处理返回结果
			ResponseUtil.write(response,resultDTO);
		}catch (Exception e) {
			logger.error(logInfo+"异常:",e);
			ResultDTO resultDTO=new ResultDTO(ResultCode.FAILED,"解绑银行卡异常");
			ResponseUtil.write(response,resultDTO);
		}
		
	}
	
	/**
	 * 掌上汇通第三方支付调用
	 * @param request
	 * @param response
	 */
	@RequestMapping(value = "/zshtThridTopUp")
	public void zshtThridTopUp(HttpServletRequest request,
			HttpServletResponse response){
		Map<String, Object> jsonMap = new HashMap<String, Object>();
		// 解密请求参数
		Map<String, String> paramsMap = CommonUtil.decryptParamters(request);
		String userId = paramsMap.get("userId");// 用户id
		String moneyOrder = paramsMap.get("moneyOrder");
		String orderdesc = paramsMap.get("orderdesc");
		String bankcard = paramsMap.get("bankcard");
		String cardusername = paramsMap.get("cardusername");
		String idno = paramsMap.get("idno");
		String cardphone = paramsMap.get("cardphone");
		String noOrder = paramsMap.get("noOrder");
		
		if (StringUtils.isBlank(userId)) {
			String result = CommonUtil.setResultStringCn(
					new HashMap<String, Object>(), Consts.ERROR_CODE,
					Consts.ErrorMsg.MSG00001,
					"userCard/zshtThridTopUp 传入用户ID为空");

			// 处理返回结果
			CommonUtil.responseJson(result, response);
			logger.debug("userCard/zshtThridTopUp 传入用户ID为空");
			return;
		}
		
		if (StringUtils.isBlank(moneyOrder)) {
			String result = CommonUtil.setResultStringCn(
					new HashMap<String, Object>(), Consts.ERROR_CODE,
					Consts.ErrorMsg.MSG00001,
					"userCard/zshtThridTopUp 传入moneyOrder为空");

			// 处理返回结果
			CommonUtil.responseJson(result, response);
			logger.debug("userCard/zshtThridTopUp 传入moneyOrder为空");
			return;
		}
		
		if (StringUtils.isBlank(orderdesc)) {
			String result = CommonUtil.setResultStringCn(
					new HashMap<String, Object>(), Consts.ERROR_CODE,
					Consts.ErrorMsg.MSG00001,
					"userCard/zshtThridTopUp 传入orderdesc为空");

			// 处理返回结果
			CommonUtil.responseJson(result, response);
			logger.debug("userCard/zshtThridTopUp 传入orderdesc为空");
			return;
		}
		if (StringUtils.isBlank(bankcard)) {
			String result = CommonUtil.setResultStringCn(
					new HashMap<String, Object>(), Consts.ERROR_CODE,
					Consts.ErrorMsg.MSG00001,
					"userCard/zshtThridTopUp 传入bankcard为空");

			// 处理返回结果
			CommonUtil.responseJson(result, response);
			logger.debug("userCard/zshtThridTopUp 传入用户ID为空");
			return;
		}
		if (StringUtils.isBlank(cardusername)) {
			String result = CommonUtil.setResultStringCn(
					new HashMap<String, Object>(), Consts.ERROR_CODE,
					Consts.ErrorMsg.MSG00001,
					"userCard/zshtThridTopUp 传入cardusername为空");

			// 处理返回结果
			CommonUtil.responseJson(result, response);
			logger.debug("userCard/zshtThridTopUp 传入cardusername为空");
			return;
		}
		if (StringUtils.isBlank(idno)) {
			String result = CommonUtil.setResultStringCn(
					new HashMap<String, Object>(), Consts.ERROR_CODE,
					Consts.ErrorMsg.MSG00001,
					"userCard/zshtThridTopUp 传入idno为空");

			// 处理返回结果
			CommonUtil.responseJson(result, response);
			logger.debug("userCard/zshtThridTopUp 传入idno为空");
			return;
		}
		if (StringUtils.isBlank(cardphone)) {
			String result = CommonUtil.setResultStringCn(
					new HashMap<String, Object>(), Consts.ERROR_CODE,
					Consts.ErrorMsg.MSG00001,
					"userCard/zshtThridTopUp 传入cardphone为空");

			// 处理返回结果
			CommonUtil.responseJson(result, response);
			logger.debug("userCard/zshtThridTopUp 传入cardphone为空");
			return;
		}
		
		Map<String, String> requestMap = new HashMap<String, String>();
		requestMap.put("userId", userId);
		requestMap.put("moneyOrder", moneyOrder);
		requestMap.put("orderdesc", orderdesc);
		requestMap.put("bankcard", bankcard);
		requestMap.put("cardusername", cardusername);
		requestMap.put("idno", idno);
		requestMap.put("cardphone", cardphone);
		requestMap.put("noOrder", noOrder);
		try{
			Map<String,String> thridResMap =ZSHTPayThridPartyFunctionUtil.zshtTopUp(requestMap);
			
			
			if (thridResMap == null
					|| "sysException".equals(thridResMap.get("rescode"))) {
				String result = CommonUtil.setResultStringCn(
						new HashMap<String, Object>(), Consts.CHECK_CODE,
						thridResMap.get("resmsg_cn"), "支付申请失败失败");
				// 处理返回结果
				CommonUtil.responseJson(result, response);
				return;
			} else if ("BusinessException".equals(thridResMap.get("rescode"))) {
				String result = CommonUtil.setResultStringCn(
						new HashMap<String, Object>(), Consts.CHECK_CODE,
						"", String.valueOf(thridResMap.get("resmsg_cn")));
				// 处理返回结果
				CommonUtil.responseJson(result, response);
				return;
			}
			
			String rescode = thridResMap.get("rescode");
			String resmsg = thridResMap.get("resmsg_cn");
			String resJson = thridResMap.get("resJson");
			if(rescode.equals("00")){
				String orderNo = thridResMap.get("orderNo");
				String paytoken = thridResMap.get("paytoken");
				jsonMap.put("orderNo", orderNo);
				jsonMap.put("paytoken", paytoken);
			}
			jsonMap.put("resmsg", resmsg);
			jsonMap.put("rescode", rescode);
			jsonMap.put("resJson", resJson);
			
			
			// 处理返回结果
			String result = JsonUtil.getJsonStringFromMap(jsonMap);
			CommonUtil.responseJson(result, response);
		}catch (Exception e) {
			logger.error("userCard/zshtThridTopUp 异常:"
					+ e.getCause());
			String result = CommonUtil.setResultStringCn(
					new HashMap<String, Object>(), Consts.ERROR_CODE,
					Consts.ErrorMsg.MSG00001,
					Message.CnDescriptionExpression.BUSINESSE_ERROR);
			CommonUtil.responseJson(result, response);
		}
	}
	
	/**
	 * 验证支付
	 * @param request
	 * @param response
	 */
	@RequestMapping(value = "/zshtThridCheckTopUp")
	public void zshtThridCheckTopUp(HttpServletRequest request,
			HttpServletResponse response){
		Map<String, Object> jsonMap = new HashMap<String, Object>();
		// 解密请求参数
		Map<String, String> paramsMap = CommonUtil.decryptParamters(request);
		String orderNo = paramsMap.get("orderNo");
		String paytoken = paramsMap.get("paytoken");
		String checkCode = paramsMap.get("checkCode");
		
		if (StringUtils.isBlank(orderNo)) {
			String result = CommonUtil.setResultStringCn(
					new HashMap<String, Object>(), Consts.ERROR_CODE,
					Consts.ErrorMsg.MSG00001,
					"userCard/zshtThridTopUp 传入orderNo为空");

			// 处理返回结果
			CommonUtil.responseJson(result, response);
			logger.debug("userCard/zshtThridCheckTopUp 传入orderNo为空");
			return;
		}
		
		if (StringUtils.isBlank(paytoken)) {
			String result = CommonUtil.setResultStringCn(
					new HashMap<String, Object>(), Consts.ERROR_CODE,
					Consts.ErrorMsg.MSG00001,
					"userCard/zshtThridTopUp 传入paytoken为空");

			// 处理返回结果
			CommonUtil.responseJson(result, response);
			logger.debug("userCard/zshtThridCheckTopUp 传入paytoken为空");
			return;
		}
		
		if (StringUtils.isBlank(checkCode)) {
			String result = CommonUtil.setResultStringCn(
					new HashMap<String, Object>(), Consts.ERROR_CODE,
					Consts.ErrorMsg.MSG00001,
					"userCard/zshtThridTopUp 传入checkCode为空");

			// 处理返回结果
			CommonUtil.responseJson(result, response);
			logger.debug("userCard/zshtThridCheckTopUp 传入checkCode为空");
			return;
		}
		
		Map<String, String> requestMap = new HashMap<String, String>();
		requestMap.put("orderNo", orderNo);
		requestMap.put("paytoken", paytoken);
		requestMap.put("checkCode", checkCode);
		
		try{
			Map<String,String> thridResMap =ZSHTPayThridPartyFunctionUtil.checkTopUp(requestMap);
			if (thridResMap == null
					|| "sysException".equals(thridResMap.get("rescode"))) {
				String result = CommonUtil.setResultStringCn(
						new HashMap<String, Object>(), Consts.CHECK_CODE,
						thridResMap.get("resmsg_cn"), "支付申请失败失败");
				// 处理返回结果
				CommonUtil.responseJson(result, response);
				return;
			} else if ("BusinessException".equals(thridResMap.get("rescode"))) {
				String result = CommonUtil.setResultStringCn(
						new HashMap<String, Object>(), Consts.CHECK_CODE,
						"", String.valueOf(thridResMap.get("resmsg_cn")));
				// 处理返回结果
				CommonUtil.responseJson(result, response);
				return;
			}
			
			String rescode = thridResMap.get("rescode");
			String resmsg = thridResMap.get("resmsg_cn");
			
			jsonMap.put("resmsg", resmsg);
			jsonMap.put("rescode", rescode);
			
			// 处理返回结果
			String result = JsonUtil.getJsonStringFromMap(jsonMap);
			CommonUtil.responseJson(result, response);
			
		}catch (Exception e) {
			logger.error("userCard/zshtThridCheckTopUp 异常:"
					+ e.getCause());
			String result = CommonUtil.setResultStringCn(
					new HashMap<String, Object>(), Consts.ERROR_CODE,
					Consts.ErrorMsg.MSG00001,
					Message.CnDescriptionExpression.BUSINESSE_ERROR);
			CommonUtil.responseJson(result, response);
		}
	}
	
	/**
	 * 查询下一个工作日
	 * @param request
	 * @param response
	 */
	@RequestMapping(value = "/queryNextWorkingDay")
	public void queryNextWorkingDay(HttpServletRequest request,
			HttpServletResponse response){
		Map<String, Object> jsonMap = new HashMap<String, Object>();
		Map<String, String> paramsMap = CommonUtil.decryptParamters(request);
		String withdrawFlag = paramsMap.get("withdrawFlag");
		
		try{
			String nextWorkingDay = "";
			Date currentDate = new Date();
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
			if(withdrawFlag.equals("ZSHTPAY")){
				nextWorkingDay = sdf.format(currentDate);
			}else{
				int hours = currentDate.getHours();
				Long cnt = this.userCardService.queryWorkingDayByCurrentDay(sdf.format(currentDate));
				if(hours<15 && cnt>0){
					nextWorkingDay = sdf.format(currentDate);
				}else{
					nextWorkingDay = this.userCardService.queryNextWorkingDay(sdf.format(currentDate));
				}
			}
			jsonMap.put("nextWorkingDay", nextWorkingDay);
			
			
			String result = CommonUtil.setResultStringCn(jsonMap, 
					Consts.SUCCESS_CODE, Consts.SUCCESS_DESCRIBE,"");
			CommonUtil.responseJson(result, response);
		}catch (Exception e) {
			logger.error("userCard/queryNextWorkingDay 异常:"
					+ e.getCause());
			String result = CommonUtil.setResultStringCn(
					new HashMap<String, Object>(), Consts.ERROR_CODE,
					Consts.ErrorMsg.MSG00001,
					Message.CnDescriptionExpression.BUSINESSE_ERROR);
			CommonUtil.responseJson(result, response);
		}
	}
	
	/**
	 * 失败发送短信
	 * @param request
	 * @param response
	 */
	@RequestMapping(value = "/sendErrorMessage")
	public void sendErrorMessage(HttpServletRequest request,
			HttpServletResponse response) {
		// 解密请求参数
		Map<String, String> paramsMap = CommonUtil.decryptParamters(request);
		String userId = paramsMap.get("userId");// 用户Id
		String content = paramsMap.get("content");// 支付类型

		if (StringUtils.isBlank(userId)) {
			String result = CommonUtil.setResultStringCn(
					new HashMap<String, Object>(), Consts.ERROR_CODE,
					Consts.ErrorMsg.MSG00001,
					Message.CnDescriptionExpression.BUSINESSE_ERROR);

			// 处理返回结果
			CommonUtil.responseJson(result, response);
			logger.debug("userCard/sendErrorMessage 传入UserId为空");
			return;
		}

		try {
			Map<String, String> requestMap = new HashMap<String, String>();
			requestMap.put("userId", userId);
			requestMap.put("content", content);
			this.userCardService.sendErrorMessage(userId, content);

			// 处理返回结果
			String result = CommonUtil.setResultStringCn(new HashMap<String,Object>(), 
					Consts.SUCCESS_CODE, Consts.SUCCESS_DESCRIBE,"");
			CommonUtil.responseJson(result, response);
		} catch (Exception e) {
			logger.error("userCard/queryCardBinLLPay 异常:" + e.getCause());
			String result = CommonUtil.setResultStringCn(
					new HashMap<String, Object>(), Consts.ERROR_CODE,
					Consts.ErrorMsg.MSG00001,
					Message.CnDescriptionExpression.BUSINESSE_ERROR);
			CommonUtil.responseJson(result, response);
		}

	}
}
